
// Definition for singly-linked list.
function ListNode(val, next) {
    this.val = (val===undefined ? 0 : val)
    this.next = (next===undefined ? null : next)
}

function createList(head) {
  let root = new ListNode(head[0]), temp = root;
  for(let i = 1; i < head.length; i++) {
    let newNode = new ListNode(head[i]);
    temp.next = newNode;
    temp = temp.next;
  }
  return root;
}
function showListNode(root) {
  while(root) {
    console.log(root.val);
    root = root.next;
  }
}
/**
 * @param {ListNode} head
 * @return {ListNode}
 */
var deleteDuplicates = function(head) {
  if(head == null)
    return head;
  // let root = createList(head), lastNode = root, nextNode = root.next;
  let lastNode = head, nextNode = head.next;
  while(nextNode) {
    if(lastNode.val == nextNode.val) {
      lastNode.next = nextNode.next;
    } else {
      lastNode = lastNode.next;
    }
    nextNode = nextNode.next;
  }
  return root;
};
let head = [1,1,2];
console.log(deleteDuplicates(head));
head = [1,1,2,3,3];
console.log(deleteDuplicates(head));
